<?php 
/**
 * name 刘杨
 */
namespace backend\controllers;
use Yii;
use yii\web\controller;
use backend\models\User;
class LoginController extends controller
{
	public $layout = false;
	//登录模块
	public function actionLogin()
	{
		$model = new User;
		return $this->render('login',['model'=>$model]);
	}
	function actionAjax()
	{
		if($data = Yii::$app->request->post())
    	{
    		$user = User::find()->where(['name'=>$data['name'],'pwd'=>$data['pwd']])->one();
    		if(empty($user))
    		{
    			exit(json_encode(array('error'=>false,'msg'=>'账号或密码错误')));
    		}
    		$save = User::findOne($user['id']);
    		$save->end_time = time();
    		$save->save();
    		$session = Yii::$app->session;
    		$session->set('admin_user',$user);
    		exit(json_encode(array('error'=>true,'msg'=>'登录成功')));
    	}
	}
}
?>